<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 2017/8/31
  Time: 17:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<html>
<head>
    <script type="text/javascript" src="../static/jquery-easyui-1.3.3/jquery.min.js"></script>
    <link href="../static/twitter-bootstrap-v2/docs/assets/css/bootstrap.css" rel="stylesheet">
    <title>订单列表</title>
    <style>
       #search_Order label{ float: left ; width: 100px;padding-left: 20px}
       #search_Order input{ float: left ; width: 100px;}
       #top_search_select input{width: 80px}
        #showTable tr td {text-align: center ;font-size: 12px ;vertical-align: middle}
       #CriteriaQuery { width: 1200px ;height: 40px;padding-top: 20px;margin-left: 50px }
       #CriteriaQuery input{padding-left: 10px;margin-right: 10px;margin-top: 3px; text-decoration:none}
       #CriteriaQuery a{margin: 0 ;padding: 0;margin-top: 0}
       a:hover {text-decoration: none;}
       #Query_Refresh{float: right;margin-right: 50px}
        #Delete_Insert_Update{float: left ;margin-left: 50px}
        #list{margin-top: 50px}
        #table_head{ border: 1px solid black }
    </style>
</head>
<body>

<jsp:include page="CriteriaQuery.jsp" flush="true"/>

<div id="Delete_Insert_Update">
    <button id="Delete" name="Delete" type="button" class="btn btn-primary" onclick="deleteOrder()" >删除订单</button>
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-whatever="@mdo">增加订单</button>
    <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModa2" data-whatever="@fat">修改订单</button>
</div>
<div id="Query_Refresh">
<button type="button" class="btn btn-primary"onclick="condition_query()">查询</button>
<button type="button" class="btn btn-primary"onclick="load_order()">刷新</button>
</div>

    <div id="list"></div>

<jsp:include page="OrderParticulars.jsp" flush="true"/>
<script>
    //加载全部订单
    $(document).ready( function () {
        load_order();
        selectFNo();
        queryOrderAll();
        qingqiu()
        condition_query()
    } ) ;

    function change() {
       var id= event.target.id;
        $.ajax({
            url:"/order/changeTkt",
            type:"post",
            dataType:"json",
            data:{
                "tktid":id
            },
            success:function(data,state){
                if (data==1){
                    alert("出票成功")

                }else{
                    alert("出票失败")
                }
                load_order();
            }
        })
    }

    function qingqiu(){

    }





    function load_order(){
        $.ajax({
            url:"/order/showOrder",
            type:"post",
            dataType:"json",
            data:{},
            success:function(data,state){

                var str ="<table id='showTable' class=\"table table-hover\" border=\"1\"  cellspacing=\"0\" align=\"center\" text-align:center>";
                str+="<tr id='table_head'>" +
                    "<td>选项</td>" +
                    "<td>订单号</td>" +
                    "<td>航班编号</td>" +
                    "<td>出发地</td>" +
                    "<td>目的地</td>" +
                    "<td>支付状态</td>" +
                    "<td>出票状态</td>" +
                    "<td>用户ID</td>" +
                    "<td>联系人</td>" +
                    "<td>联系人手机号</td>" +
                    "<td>航班日期</td>" +
                    "<td>仓位</td>" +
                    "<td>订单价格</td>" +
                    "<td>创建时间</td>" +
                    "<td colspan='2'>编辑</td></tr>";
                  $.each(data,function(i,item){
                    if (item.tktstatus==0){
                       var tktstatus="未出票";
                    }else if(item.tktstatus==1){
                        var tktstatus ="已出票";
                       }

                    str+="<tr>";
                    str+="<td>"+"<input  id='ordercheck' type='checkbox' value='"+item.id+"'/>" +"</td>";
                    str+="<td>"+item.id+"</td>";
                    str+="<td>"+item.flightno+"</td>";
                    str+="<td>"+item.deptcity+"</td>";
                    str+="<td>"+item.arrcity+"</td>";
                    str+="<td>"+item.paystatus+"</td>";
                    str+="<td>"+item.tktstatus+"</td>";
                    str+="<td>"+item.userid+"</td>";
                    str+="<td>"+item.linkman+"</td>";
                    str+="<td>"+item.linkphone+"</td>";;
                    var flightdate=date_reversal(item.flightdate);
                    str+="<td>"+flightdate+"</td>";
                    str+="<td>"+item.flightcabin+"</td>";;
                    str+="<td>"+item.price+"</td>";
                    var creatdate=date_reversal(item.createtime);
                    str+="<td>"+creatdate+"</td>";
                    str+="<td>"+"<input onclick='change()' name='tktstatus' type=\"button\" id='"+item.id+"' class=\"btn btn-primary\"value=\""+tktstatus+"\"/>" +"</td>";
                    str+="<td>"+"<input onclick='queryOrderAll()' type=\"button\" id='"+'Ao'+item.id+"'class=\"btn btn-primary\" data-toggle=\"modal\" data-target=\"#exampleModal\" data-whatever=\"@mdo\"value='订单详情'/>" +"</td>";

                    str+="</tr>";

                    $("#list").html(str);
                      });
                        str+="</table>"


                         }
                          });
                             }
   function date_reversal(var1) {
       var date = new Date(var1);
       Y = date.getFullYear() + '-';
       M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
       D = date.getDate() + ' ';
       h = date.getHours() + ':';
       m = date.getMinutes() + ':';
       s = date.getSeconds();
       console.log(Y+M+D+h+m+s);
       return Y+M+D+h+m+s;

   }
    function deleteOrder() {

        var array = new Array(); //用于保存 选中的那一条数据的ID
        var flag; //判断是否一个未选
        $("input[type='checkbox']:checked").each(function () {
            if (array.length!=null) { //判断是否选中
               flag = true; //只要有一个被选择 设置为 true
           }
        });
        if (flag) {
            $("input[type='checkbox']:checked").each(function() {
                //遍历所有的name为selectFlag的 checkbox
                    array.push($(this).val()); //将选中的值 添加到 array中

            })
//          传参数给后台
        } else {
            alert("请至少选择一个用户");
        }
        $.ajax({
            url:"/order/deleteOrder",
            type:"post",
            dataType:"text",
            data:{
                'deleteArray':array
            },
            success:function(type,state){
                 if (type!=null){
                     alert("删除成功");
                     load_order();

                 }else
                 {
                     alert("删除失败")
                     load_order();
                 }

            }
        });



    }

</script>
</body>
</html>
